class_name CharacterEntityData
extends EntityData

@export_group("EntityAttribute")
@export var max_health:int = 100:
	get:
		return clamp(max_health,1,2**31-1) 
	set(value):
		max_health = value
		data_changed.emit("max_health")
@export var max_speed:float = 100:
	get:
		return clamp(max_speed,0,2**31-1) 
	set(value):
		max_speed = value
		data_changed.emit("max_speed")
@export var speed_acc:float = 300:
	get:
		return clamp(speed_acc,0,2**31-1) 
	set(value):
		speed_acc = value
		data_changed.emit("speed_acc")
@export var move_speed_scale:float = 1:
	get:
		return clamp(move_speed_scale,0,2**31-1)
	set(value):
		move_speed_scale = value
		data_changed.emit("move_speed_scale")
@export var defense:int = 100:
	get:
		return clamp(defense,0,StaticValue.INT_MAX)
	set(value):
		defense = value
		data_changed.emit("defense")
@export var damage_scale:float = 1:
	get:
		return damage_scale
	set(value):
		damage_scale = value
		data_changed.emit("damage_scale")
@export var recover_scale:float = 1:
	get:
		return recover_scale
	set(value):
		recover_scale = value
		data_changed.emit("recover_scale")
@export var crit_rate:float = 0:
	get:
		return clamp(crit_rate,0,100)
	set(value):
		crit_rate = value
		data_changed.emit("crit_rate")
@export var crit_damage_scale = 2:
	get:
		return crit_damage_scale
	set(value):
		crit_damage_scale = value
		data_changed.emit("crit_damage_scale")
@export var attack_speed:int = 100:
	get:
		return clamp(attack_speed,1,StaticValue.INT_MAX)
	set(value):
		attack_speed = value
		data_changed.emit("attack_speed")
@export var reload_reduction:int = 0:
	get:
		return clamp(reload_reduction,0,StaticValue.INT_MAX)
	set(value):
		reload_reduction = value
		data_changed.emit("reload_reduction")
@export var cooling_reduction:int = 0:
	get:
		return clamp(cooling_reduction,0,StaticValue.INT_MAX)
	set(value):
		cooling_reduction = value
		data_changed.emit("cooling_reduction")
@export var default_camp:GameEnum.Camp = GameEnum.Camp.None:
	get:
		return default_camp
	set(value):
		default_camp = value
		data_changed.emit("default_camp")
@export var max_stamina:float = 100:
	get:
		return clamp(max_stamina,0,INF)
	set(value):
		max_stamina = value
		data_changed.emit("max_stamina")
@export var stamina_reply_per_second:float = 40:
	get:
		return clamp(stamina_reply_per_second,0,INF)
	set(value):
		stamina_reply_per_second = value
		data_changed.emit("stamina_reply_per_second")
@export var is_sky_entity:bool = false:
	get:
		return is_sky_entity
	set(value):
		is_sky_entity = value
		data_changed.emit("is_sky_entity")
@export var is_sky_view:bool = false:
	get:
		return is_sky_view
	set(value):
		is_sky_view = value
		data_changed.emit("is_sky_view")
@export_group("Dodge")
@export var dodge_move_speed_scale:float = 2:
	get:
		return dodge_move_speed_scale
	set(value):
		dodge_move_speed_scale = value
		data_changed.emit("dodge_move_speed_scale")
@export var dodge_duration:float = 0.1:
	get:
		return dodge_duration
	set(value):
		dodge_duration = value
		data_changed.emit("dodge_duration")
@export var dodge_stamina_consume_per_second:float = 50:
	get:
		return clamp(dodge_stamina_consume_per_second,0,INF)
	set(value):
		dodge_stamina_consume_per_second = value
		data_changed.emit("dodge_stamina_consume_per_second")
@export var dodge_stamina_consume_increase_per_second:float = 10:
	get:
		return clamp(dodge_stamina_consume_increase_per_second,0,INF)
	set(value):
		dodge_stamina_consume_increase_per_second = value
		data_changed.emit("dodge_stamina_consume_increase_per_second")
@export_group("")
@export_group("Weapon")
@export var default_weapon_name:String:
	get:
		return default_weapon_name
	set(value):
		default_weapon_name = value
		data_changed.emit("default_weapon_name")
@export_range(0,8) var weapon_max_amount:int = 0:
	get:
		return clamp(weapon_max_amount,0,8)
	set(value):
		weapon_max_amount = value
		data_changed.emit("weapon_max_amount")
@export_group("")
@export_group("LayerMask")
@export_flags_2d_physics var layer_mask_friendly = (1<<0)
@export_flags_2d_physics var layer_mask_hostile = (1<<1)
@export_flags_2d_physics var layer_mask_neutral = (1<<2)
@export_flags_2d_physics var layer_mask_obstacle = (1<<4) | (1<<6) | (1<<7) | (1<<8) | (1<<9)
@export_flags_2d_physics var layer_mask_sky_obstacle = (1<<7)
@export_flags_2d_navigation var layer_navigation:int:
	get:
		return layer_navigation
	set(value):
		layer_navigation = value
		data_changed.emit("layer_navigation")
@export_group("")
@export_group("Anim")
@export var default_anim_name:String = "idle":
	get:
		return default_anim_name
	set(value):
		default_anim_name = value
@export_group("")
@export_group("Other")
@export var sprite:Texture2D:
	get:
		return sprite
	set(value):
		sprite = value
@export_group("")
#region 信号
#endregion
#region 方法
# 得到缩放后的移动速度
func get_scale_move_speed() -> float:
	return max_speed * move_speed_scale
# 得到伤害倍率
func get_damage_multiplier(is_crit:bool) -> float:
	var damage_mul = 1.0 * damage_scale
	if is_crit:
		damage_mul *= crit_damage_scale
	return damage_mul
# 得到攻击速度加成
func get_attack_speed_scale() -> float:
	return attack_speed * 1.0 / 100.0
# 得到换弹时间缩减比例
func get_reload_reduction_scale() -> float:
	return 100.0/(100.0 + reload_reduction)
# 得到冷却缩减比例
func get_cooling_reduction_scale() -> float:
	return 100.0/(100.0 + cooling_reduction)
# 得到减伤比例
func get_reduce_damage_scale() -> float:
	return 100.0/(100.0 + defense)
# 得到恢复比例
func get_recover_scale() -> float:
	return recover_scale
# 根据是否是飞行单位获得对应的障碍物LayerMask
func get_obstacle_layer_mask() -> int:
	if is_sky_entity:
		return get_layer_mask_by_tag("Obstacle")
	else:
		return get_layer_mask_by_tag("Sky_Obstacle")
# 根据tag得到对应的LayerMask
func get_layer_mask_by_tag(tag:String) -> int:
	match tag:
		"None":return 0
		"Friendly":return layer_mask_friendly
		"Hostile":return layer_mask_hostile
		"Neutral":return layer_mask_neutral
		"Obstacle":return layer_mask_obstacle
		"Sky_Obstacle":return layer_mask_sky_obstacle
		_:return 0

func get_temp_data(source_entity:Node, source:Node,value:float,is_must_crit:bool = false,can_counter:bool = false):
	var is_crit = true if is_must_crit or (crit_rate > 0 and GameManager.rng_randf() < crit_rate / 100.0) else false
	var final_value = abs(value)
	if value < 0:
		final_value = final_value * get_damage_multiplier(is_crit)
	elif value > 0:
		final_value = final_value * get_recover_scale()
	var temp_data = TempEntityData.new(source_entity,source, final_value, is_crit,can_counter)
	return temp_data
#endregion
